var network = {
	http : Ti.Network.createHTTPClient({ validatesSecureCertificate:false, timeout:Ti.App.config.connection_timeout }),
	
	getServerDataWithHandlers: function (url,onResponseOkHandler,onResponseKoHandler){
		if(Ti.Network.networkType == Ti.Network.NETWORK_NONE){
			var alertDialog = Titanium.UI.createAlertDialog({
				title: L('WARNING'),
				message: L('Your device is not online.'),
				buttonNames: ['OK']
	        });
			Ti.App.fireEvent(onResponseKoHandler,{status:'no network'});
			alertDialog.show();
		    return;
		}
		Ti.API.info("getServerDataWithHandlers called");		
		
		this.http.shouldUseRFC2616RedirectBehaviour = false;
		this.http.shouldRedirect = false;
		
		this.http.open('GET',url);
		this.http.setRequestHeader('referer',url);
		this.http.setRequestHeader('User-Agent',Ti.App.config.user_agent);
		this.http.onerror = function(e){ Ti.App.fireEvent(onResponseKoHandler,e.error); };
		
		this.http.onload = function(e){
			if(this.status == 200){	Ti.App.fireEvent(onResponseOkHandler,{text:this.responseText}); }
			else{					Ti.App.fireEvent(onResponseKoHandler,{status:this.status}); }
		};
		
		this.http.send();
	},
	
	getTorrents : function (){
		Ti.API.info("getTorrents called");	
		this.getServerDataWithHandlers(Ti.App.config.url_torrents_gae,'torrentDownloadOk','torrentDownloadKo');
	},

	getComentaris : function (idIdea){
		Ti.API.info("getComentaris called");
		this.getServerDataWithHandlers(Ti.App.config.url_torrents_comentaris_gae + idIdea,'comentarisDownloadOk','comentarisDownloadKo');
	}
};